Back

Git & GitHub: Basics πŸš€

Starting with Git 🌱

git init

Initializes a new Git repository in your project folder. Creates a new time machine for your code!

Pushing Code to GitHub πŸ“€

git add .

Adds all your changes to a staging area. Stages your changes for commit (turns them green in some editors)

git commit -m "Your message here"

Takes a snapshot of your changes. Saves your changes locally

git push origin main

 Sends your changes to GitHub. Updates the online repository.

Pulling Code from GitHub πŸ“₯

git pull origin main

 Downloads and merges changes from GitHub. Updates your local environment with the latest code

Merging Changes from GitHub 🧩

git fetch origin

Downloads changes without merging. Gets the latest code without changing your local files

git merge origin/main

Merges the changes into your local branch. Combines the latest code with your local changes

Ignoring Local Changes and Getting Code from GitHub πŸ™ˆ

git fetch origin

 Downloads the latest code.

git reset --hard origin/main

 Ignores your local changes and replaces them with the code from GitHub. Wipes local changes and matches the online repository

Saving Local Changes but Merging from GitHub πŸ’Ύ

git stash

 Temporarily saves your local changes. Puts your changes aside

git pull origin main

Downloads and merges the latest code

git stash apply

Brings back your saved local changes. Reapplies your changes on top of the latest code.

Some code editors show uncommitted changes in red, staged changes in green, etc. It's like a traffic light for your code! 🚦

Note: Replace main with your branch name if it's different.

Resources πŸ“š

Posted To avatar
Programming
• 8 months ago

Please login or create an account to post a comment.

No Posts
No comments yet...